package com.jack.thinking.thread.core._3;

import java.util.Date;

public class InheritableThreadLocalReWrite {
	public static MyInheritableThreadLocalObject o = new MyInheritableThreadLocalObject();
	public static void main(String[] args) throws Exception {
		System.out.println(o.get());
		Thread.sleep(1000L);
		o.set(new Date().toString());
		System.out.println(o.get());
		new Thread() {
			public void run() {
				System.out.println("child-" + o.get());
				try {
					Thread.sleep(1000L);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				System.out.println("child-" + o.get());
			};
		}.start();
		try {
			Thread.sleep(500L);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		o.set(new Date().toString());
		System.out.println("ending ...." + o.get());
	}
}


class MyInheritableThreadLocalObject extends InheritableThreadLocal<String>{
	@Override
	protected String initialValue() {
		return new Date().toString();
	}
	
	@Override
	protected String childValue(String parentValue) {
		return parentValue + " child ";
	}
}